#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=("webinterface-upload-button")
pkgdesc="A simple upload button for the web interface"
url="https://github.com/rM-self-serve/webinterface-upload-button"
pkgver=1.1.1-3
timestamp=2023-12-16T15:35:49Z
section="utils"
maintainer="rM-self-serve <122753594+rM-self-serve@users.noreply.github.com>"
license=MIT

source=(
    "$url"/archive/1d28b2d91c0179059017696ae5a33aa49e1e7c7d.zip
)
sha256sums=(
    f967cad7607da6458cb0e307b662db66026747922f98ad19f7e2265b9cab1f47
)

package() {
    install -D -m 755 -t "$pkgdir"/opt/bin "$srcdir/$pkgname"
    install -D -m 644 -t "$pkgdir"/usr/share/remarkable/webui/ "$srcdir/$pkgname.js"

    mkdir -p "$pkgdir"/opt/share/toltec/reenable.d
    touch "$pkgdir"/opt/share/toltec/reenable.d/"$pkgname"
}

configure() {
    echo
    echo "Applying webinterface-upload-button"
    webinterface-upload-button apply -y > /dev/null
    echo "Success"
    echo
}

_restore() {
    echo
    echo "Reverting webinterface-upload-button"
    webinterface-upload-button revert -y > /dev/null
    echo "Success"
    echo
}

preremove() {
    _restore
}

preupgrade() {
    _restore
}
